package com.zhsj.OkeHomeConsumption.ui.activity.citypartner.mvp;

import android.content.Context;
import android.support.v4.app.FragmentActivity;

import com.hjq.base.BaseDialog;
import com.hjq.dialog.WaitDialog;
import com.zhsj.OkeHomeConsumption.common.Constants;
import com.zhsj.OkeHomeConsumption.common.OkeHomeConsumptionApi;
import com.zhsj.OkeHomeConsumption.network.HttpClient;
import com.zhsj.OkeHomeConsumption.network.JsonResponseHandler;
import com.zhsj.OkeHomeConsumption.other.TimeChecker;
import com.zhsj.OkeHomeConsumption.other.TimeOutHandler;
import com.zhsj.OkeHomeConsumption.other.URLEntity;
import com.zhsj.OkeHomeConsumption.utils.SignUtil;

import java.util.HashMap;

/**
 * * <p>文件描述：城市合伙人商家招募逻辑层<p>
 */
public class MerchantsWeihuRecruitPresenter {
    public MerchantsWeihuRecruitUIInterFace mUIInterFace;
    private BaseDialog pDialogUtils = null;
    public TimeChecker timeChecker;
private Context conteng;
    public MerchantsWeihuRecruitPresenter(Context mContext, MerchantsWeihuRecruitUIInterFace uiInterface) {
        mUIInterFace = uiInterface;
        pDialogUtils = new BaseDialog(mContext);
        conteng = mContext;
        timeChecker = new TimeChecker(TimeOutHandler.timeOutHandler, Constants.TIME_OUT);
    }
    /*
     * 预览协议
     * */
    public void ContractPreViewGet(String lifeUserTye,String otherUserId) {
        HashMap<String, String> paramMaps = new HashMap<String, String>();
        final HashMap<String, String> mLogOnHashMap = new HashMap<String, String>();
        mLogOnHashMap.put("v", Constants.APPVERSION);
        mLogOnHashMap.put("t", Constants.TIME);
        mLogOnHashMap.put("deviceToken", Constants.DEVICETOKEN);
        mLogOnHashMap.put("client", Constants.CLIENT);
        mLogOnHashMap.put("deviceId", URLEntity.getInstance().getImei());
        mLogOnHashMap.put("platform", Constants.PLAFORM);

        mLogOnHashMap.put("lifeUserType", lifeUserTye);
        paramMaps.put("lifeUserType", lifeUserTye);

        mLogOnHashMap.put("otherUserId", otherUserId);
        paramMaps.put("otherUserId", otherUserId);

        // 网络计时器及线程
        TimeOutHandler.pDialogUtils = pDialogUtils;
        pDialogUtils.show();
        timeChecker.start();
        // 获取sign签名
        Constants.SIGN = SignUtil.getInstance().getSign(mLogOnHashMap);
        HttpClient.get(OkeHomeConsumptionApi.ELVDOU_CONTRACTSIGNPREVIEW , paramMaps, new JsonResponseHandler() {
            @Override
            public void onSuccess(int statusCode, String content) {
                super.onSuccess(statusCode, content);
                timeChecker.check();
                pDialogUtils.dismiss();
                TimeOutHandler.pDialogUtils = null;
                mUIInterFace.ContractPreViewGet(content);
            }

            @Override
            public void onFailure(Throwable e) {
                super.onFailure(e);
                timeChecker.check();
                pDialogUtils.dismiss();
                TimeOutHandler.pDialogUtils = null;
            }
        });
    }

    /**
     * 城市合伙人商家招募
     *
     * @param
     */
    public void QueryByCityCoptnerGet( long cityCoptnerId,int pageNum,String categoryLevel1) {
        HashMap<String, String> paramMaps = new HashMap<String, String>();
        final HashMap<String, String> mLogOnHashMap = new HashMap<String, String>();
        mLogOnHashMap.put("v", Constants.APPVERSION);
        mLogOnHashMap.put("t", Constants.TIME);
        mLogOnHashMap.put("deviceToken", Constants.DEVICETOKEN);
        mLogOnHashMap.put("client", Constants.CLIENT);
        mLogOnHashMap.put("deviceId", URLEntity.getInstance().getImei());
        mLogOnHashMap.put("platform", Constants.PLAFORM);


        paramMaps.put("cityCopartnerUserId",String.valueOf(cityCoptnerId));
        mLogOnHashMap.put("cityCopartnerUserId", String.valueOf(cityCoptnerId));

        paramMaps.put("categoryLevel1",String.valueOf(categoryLevel1));
        mLogOnHashMap.put("categoryLevel1", String.valueOf(categoryLevel1));
        //页码
        paramMaps.put("pageNum",String.valueOf(pageNum));
        mLogOnHashMap.put("pageNum", String.valueOf(pageNum));

        //每页数量
        paramMaps.put("pageSize",String.valueOf(10));
        mLogOnHashMap.put("pageSize", String.valueOf(10));


        // 网络计时器及线程
        TimeOutHandler.pDialogUtils = pDialogUtils;
        pDialogUtils.show();
        timeChecker.start();
        // 获取sign签名
        Constants.SIGN = SignUtil.getInstance().getSign(mLogOnHashMap);
        HttpClient.get(OkeHomeConsumptionApi.ELVDOU_SHOPDEFEND, paramMaps, new JsonResponseHandler() {
            @Override
            public void onSuccess(int statusCode, String content) {
                super.onSuccess(statusCode, content);
                timeChecker.check();
                TimeOutHandler.pDialogUtils.dismiss();
                TimeOutHandler.pDialogUtils = null;
                mUIInterFace.QueryByCityCoptnerGet(content);
            }

            @Override
            public void onFailure(Throwable e) {
                super.onFailure(e);
                timeChecker.check();
                TimeOutHandler.pDialogUtils.dismiss();
                TimeOutHandler.pDialogUtils = null;
            }
        });
    }

    /**
     * 获取经营类别
     *
     * @param
     */
    public void MerchantTypeGet() {
        HashMap<String, String> paramMaps = new HashMap<String, String>();
        final HashMap<String, String> mLogOnHashMap = new HashMap<String, String>();
        mLogOnHashMap.put("v", Constants.APPVERSION);
        mLogOnHashMap.put("t", Constants.TIME);
        mLogOnHashMap.put("deviceToken", Constants.DEVICETOKEN);
        mLogOnHashMap.put("client", Constants.CLIENT);
        mLogOnHashMap.put("deviceId", URLEntity.getInstance().getImei());
        mLogOnHashMap.put("platform", Constants.PLAFORM);
        /**
         *
         * categoryId
         * 分类标识,如果为空则检索一级分类,否则检索子级
         * */
        // 网络计时器及线程
        TimeOutHandler.pDialogUtils = pDialogUtils;
        pDialogUtils.show();
        timeChecker.start();
        // 获取sign签名
        Constants.SIGN = SignUtil.getInstance().getSign(mLogOnHashMap);
        HttpClient.get(OkeHomeConsumptionApi.ELVDOU_QUERYBYPARENTID, paramMaps, new JsonResponseHandler() {
            @Override
            public void onSuccess(int statusCode, String content) {
                super.onSuccess(statusCode, content);
                timeChecker.check();
                pDialogUtils.dismiss();
                TimeOutHandler.pDialogUtils = null;
                mUIInterFace.MerchantTypeGet(content);
            }

            @Override
            public void onFailure(Throwable e) {
                super.onFailure(e);
                timeChecker.check();
                pDialogUtils.dismiss();
                TimeOutHandler.pDialogUtils = null;
            }
        });
    }


}
